import { _decorator, Component, instantiate, Label, Node, Prefab } from 'cc';
import { LayerBase } from './LayerBase';
import { UserInfo } from './UserInfo';
import { StartSceneGameMgr } from './StartSceneGameMgr';
import { UILayerMgr } from './UILayerMgr';
import { EquipCellItem } from './EquipCellItem';
import { PetItem } from './PetItem';
import { Start } from './Start';
import { rewardEnum } from '../Enum';
import { AudioMgr } from '../utils/AudioMgr';
const { ccclass, property } = _decorator;

@ccclass('SalvagePetPanel')
export class SalvagePetPanel extends LayerBase {
   
    @property(Node)
    petContent:Node;
    @property(Prefab)
    petItemPre:Prefab;
    @property(Label)
    getSalvageValue:Label;

    pet;

    init(somedData?: any): void {
        this.pet=somedData;
        this.petContent.removeAllChildren();
        let pre=instantiate(this.petItemPre)
        pre.setParent(this.petContent);
        pre.getComponent(PetItem).init(somedData,true);

        this.getSalvageValue.string=somedData.salvageGet+"";

    }

    onclickSalvageBtn() {
        AudioMgr.ins.playOneShot("audio/clickBtn",0.8);

        UserInfo.crystalMun+=this.pet.salvageGet;
        let rewardCongfi=UserInfo.rewardCongfiDic.get(rewardEnum.crystal);
        rewardCongfi.count=this.pet.salvageGet;
        UILayerMgr.getIns.openUILayer("getRewardPanel", rewardCongfi);
        
        UserInfo.hasPetDic.delete(this.pet.petId)
        StartSceneGameMgr.ins.saveGameDate();
        UILayerMgr.getIns.resfreshUI("petPanel")
        Start.ins.initHomePanel();
        UILayerMgr.getIns.closeUILayer("desPetPanel");
        UILayerMgr.getIns.closeUILayer(this.node.name);
    }

}


